<?php 

class Ext_User_Show
{
    protected $_userId;
    
    public $userId = 0;
    public $roleId = 1;
    public $role;
    public $acl;
    public $nickname;
    public $avatar;
    public $account;
    public $url;
    
    public function __construct($userId)
    {
        $userId = intval($userId);
        
        $this->_userId = $userId;
        
        $this->_build($userId);
    }
    
    private function _build($userId)
    {
        $this->userId   = $userId;
        
        $userRow = App_Model_DbTable_User::getInstance()->getRowById($userId);
        if(!$userRow)
        {
            return "";
        }
        $this->roleId   = $userRow['roleId'];
        $this->nickname = $userRow['nickname'];
    }

    public function buildUrl()
    {
        $this->url = Ext_Url::getInstance()->user($this->_userId);
        return $this;
    }

    public function buildAvatar()
    {
        $this->avatar = new Ext_Avatar_Show($this->_userId);
        
        return $this;
    }

    public function buildRole()
    {
        $this->role = new Ext_Role();
        
        $user = App_Model_DbTable_User::getInstance()->getRowById($this->_userId);
        if(!$user)
        {
            return $this;
        }
        $roleId   = $user['roleId'];
        
        $this->role->build($roleId);
        
        return $this;
    }
    
    public function buildAccount()
    {
        $this->account = new Ext_Account($this->_userId);
        
        return $this;
    }
    
    public function buildAcl()
    {
        $roleId = $this->buildRole()->role->roleId;
        
        $this->acl = Ext_Acl::getInstance()->build($roleId);
        
        return $this;
    }
}